<html>
<head><meta charset="utf-8"><title>Closure and higher ranked lifetime · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html">Closure and higher ranked lifetime</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="192968375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/192968375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#192968375">(Apr 05 2020 at 17:09)</a>:</h4>
<p>Hello! I am having trouble expressing correct bounds for higher ranked lifetime in closure. I managed to "minify" my issue here: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=2004ab01f15aa17096984f22de411ebf" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=2004ab01f15aa17096984f22de411ebf">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=2004ab01f15aa17096984f22de411ebf</a> <br>
Its still not very small,  i am sorry :/</p>



<a name="192968421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/192968421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#192968421">(Apr 05 2020 at 17:10)</a>:</h4>
<p>(by the way, the code times out in playground in nightly but not on stable, maybe there a perf regression in nightly?)</p>



<a name="192968548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/192968548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#192968548">(Apr 05 2020 at 17:14)</a>:</h4>
<p>I _think_ what i want  to express is something like <code>for&lt;'a&gt; |ctx: &amp;'a ExecCtx&lt;'a&gt;| { ... }</code> but i am not sure and its not even valid syntax ^^</p>



<a name="192968602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/192968602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#192968602">(Apr 05 2020 at 17:16)</a>:</h4>
<p>The perf regression should be fixed in the next nightly</p>



<a name="193015089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193015089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193015089">(Apr 06 2020 at 09:20)</a>:</h4>
<p>So I made it work using GAT and adding a higher ranked lifetime to the <code>ExecCtx</code> associated type: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=29a19937604b78a9136fff0c3fae5e97" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=29a19937604b78a9136fff0c3fae5e97">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=29a19937604b78a9136fff0c3fae5e97</a></p>



<a name="193015186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193015186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193015186">(Apr 06 2020 at 09:20)</a>:</h4>
<p>But i would really like to have it working on stable. Is there a way around? Or maybe another way to look at the problem?</p>



<a name="193021585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193021585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193021585">(Apr 06 2020 at 10:26)</a>:</h4>
<p>I reduced it here: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=243dea1e7c1493bedd6e376ed12a2b21" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=243dea1e7c1493bedd6e376ed12a2b21">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=243dea1e7c1493bedd6e376ed12a2b21</a></p>
<p>It really seems like a problem with higher ranked lifetime and closure composition.<br>
I think i would like to tell the compiler that in the <code>compose</code> function the higher ranked lifetime is the same for both the inner and the outer closure</p>



<a name="193021650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193021650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193021650">(Apr 06 2020 at 10:26)</a>:</h4>
<p>(and its not about GAT anymore)</p>



<a name="193053833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193053833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193053833">(Apr 06 2020 at 14:55)</a>:</h4>
<p>I was able to get it to compile without GAT: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=db7a1e9d9bdaf990f1ba78974ce9db38" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=db7a1e9d9bdaf990f1ba78974ce9db38">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=db7a1e9d9bdaf990f1ba78974ce9db38</a></p>



<a name="193053888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193053888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193053888">(Apr 06 2020 at 14:55)</a>:</h4>
<p>Not sure if this still applies in your actual context</p>



<a name="193054042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193054042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193054042">(Apr 06 2020 at 14:56)</a>:</h4>
<p>I removed the nll feature and it made no difference, so now it works on stable: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=db7a1e9d9bdaf990f1ba78974ce9db38" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=db7a1e9d9bdaf990f1ba78974ce9db38">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=db7a1e9d9bdaf990f1ba78974ce9db38</a></p>



<a name="193054317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193054317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193054317">(Apr 06 2020 at 14:58)</a>:</h4>
<p>The originating change was converting:</p>
<div class="codehilite"><pre><span></span>pub trait Compiler: Sized {
    type ExecCtx&lt;&#39;e&gt;;
    ...
}
</pre></div>


<p>to</p>
<div class="codehilite"><pre><span></span>pub trait Compiler&lt;&#39;a&gt;: Sized {
    type ExecCtx: &#39;a;
    ...
}
</pre></div>



<a name="193068007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Closure%20and%20higher%20ranked%20lifetime/near/193068007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Closure.20and.20higher.20ranked.20lifetime.html#193068007">(Apr 06 2020 at 16:38)</a>:</h4>
<p>Ill look into it!!! Thank you for the help</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>